/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package GUI;

import Model.Client;
import Model.Config;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import javax.swing.table.AbstractTableModel;

/**
 *
 * @author KoBE
 */
public class ClientTableModel extends AbstractTableModel{

    private List<Client> clients = new ArrayList<Client> ();
    private Locale locale = Config.LOCALE;    
    

    public void setClients(List<Client> allClients){
        this.clients = allClients;
    }
    @Override
    public int getRowCount() {
        return clients.size();
    }

    @Override
    public int getColumnCount() {
        return 4;
    }
    public void removeAll() {
        clients.removeAll(clients);
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        Client client = clients.get(rowIndex);
        switch (columnIndex) {
            case 0:
                return client.getName();
            case 1:
                return RBUtils.getBoundle(client.getGoldMember());
            case 2:
                return RBUtils.getBoundle(client.getBlackListed());
            case 3:
                return client.getRegistrationDate();
            default:
                throw new IllegalArgumentException("columnIndex");
        }
    }

    @Override
    public Class<?> getColumnClass(int columnIndex) {
    switch (columnIndex) {
        case 0:
            return String.class;
        case 1:
            return String.class;
        case 2:
            return String.class;
        case 3:
            return Date.class;

        default:
            throw new IllegalArgumentException("columnIndex");
        }
    }
        @Override
    public String getColumnName(int columnIndex) {

    switch (columnIndex) {
            case 0:
                return RBUtils.getBoundle("name");
            case 1:
                return RBUtils.getBoundle("goldMember");
            case 2:
                return RBUtils.getBoundle("blackListed");
            case 3:
                return RBUtils.getBoundle("registrationDate");
        default:
            throw new IllegalArgumentException("columnIndex");
        }
    }

    public void addClient(Client client) {
    clients.add(client);
    int lastRow = clients.size() - 1;
    fireTableRowsInserted(lastRow, lastRow);
    }

    public Client getValueAt(int rowIndex) {
        return clients.get(rowIndex);
    }
    
    public void deleteValue(Client client) {
        clients.remove(client);
        fireTableDataChanged();
    }

    @Override
    public boolean isCellEditable(int rowIndex, int columnIndex) {
        switch (columnIndex) {
            case 0:
            case 1:
            case 2:
            case 3:
                return false;
            default:
                throw new IllegalArgumentException("columnIndex");
        }
    }
}
